package cn.creat.ht.controller;

import cn.creat.ht.pojo.Page;
import cn.creat.ht.service.InforGetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/5 0005.
 */
@Controller
@RequestMapping("/infor")
public class InformationController {

    @Autowired
    private InforGetService inforGetService;

    @RequestMapping(value = "/getTalkInfor")
    public void getTalkInfor(HttpServletResponse response) throws Exception {
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter writer = response.getWriter();
        String body = inforGetService.getTalkInfor();
        writer.write(body);
        writer.flush();
        writer.close();
    }

    @RequestMapping(value="/getArticle")
    public void getArticle(String id, HttpServletResponse response) throws Exception {
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter writer = response.getWriter();
        String body = inforGetService.getArticle(id);
        writer.write(body);
        writer.flush();
        writer.close();
    }
    @RequestMapping(value = "/getNext")
    public void getNext(Integer pageNum, HttpServletResponse response) throws Exception {
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter writer = response.getWriter();
        String body = inforGetService.getNextPage(pageNum);
        writer.write(body);
        writer.flush();
        writer.close();
    }

    @RequestMapping(value = "/getPre")
    public void getPre(Integer pageNum, HttpServletResponse response) throws Exception {
        response.setContentType("application/json; charset=UTF-8");
        response.setCharacterEncoding("utf-8");
        PrintWriter writer = response.getWriter();
        String body = inforGetService.getPrePage(pageNum);
        writer.write(body);
        writer.flush();
        writer.close();
    }
//    @RequestMapping(value="/getProvince")
//    public @ResponseBody Map<String,String> getProvince() throws Exception{
//        return inforGetService.getProvince();
//    }
//
//    @RequestMapping(value="/getTalkInfor")
//    public @ResponseBody Page getTalkInfor(String province, int pageNum) throws Exception{
//        return inforGetService.getTalkInfor(province, pageNum);
//    }
//
//    @RequestMapping(value="/getArticle")
//    public void getArticle(String article, HttpServletResponse response) throws Exception {
//        response.setContentType("text/html; charset=UTF-8");
//        response.setCharacterEncoding("utf-8");
//        PrintWriter writer = response.getWriter();
//        String body = inforGetService.getArticle(article);
//        writer.write(body);
//        writer.flush();
//        writer.close();
//    }
}
